//package com.example.pool.netty;
//
//import com.alibaba.fastjson.JSON;
//import io.netty.buffer.Unpooled;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.SimpleChannelInboundHandler;
//import io.netty.handler.codec.http.*;
//import org.apache.http.HttpVersion;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//
//public class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
//    private static final Logger logger = LoggerFactory.getLogger(HttpServerHandler.class);
//
//    @Override
//    protected void channelRead0(ChannelHandlerContext channelHandlerContext, FullHttpRequest fullHttpRequest) throws Exception {
//        System.out.println(fullHttpRequest.getUri().toString());
//        if ("/api/test".equals(fullHttpRequest.getUri())) {
//            {
//                writeResponse(ctx, false, JSON.toJSONString(ResponseVo.success()).getBytes());
//            }
//        } else {
//            writeResponse(channelHandlerContext, false, JSON.toJSONString(ResponseVo.error()).getBytes());
//        }
//    }
//
//
//    private void writeResponse(ChannelHandlerContext ctx, boolean keepAlive, byte[] responseBytes) {
//        FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(responseBytes));
//        response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=UTF-8");       // HttpHeaderValues.TEXT_PLAIN.toString()
//        response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
//        if (keepAlive) {
//            response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
//        }
//        ctx.writeAndFlush(response);
//    }
//
//    @Override
//    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
//        ctx.flush();
//    }
//
//    @Override
//    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
//        logger.error("Jobs rpc provider netty_http server caught exception", cause);
//        ctx.close();
//    }
//
//    @Override
//    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
//        if (evt instanceof IdleStateEvent) {
//            ctx.channel().close();      // close idle channel
//            logger.debug("Jobs rpc provider netty_http server close an idle channel.");
//        } else {
//            super.userEventTriggered(ctx, evt);
//        }
//    }
//
//
//
//
//}
//
//
